package com.k.demo.controller;

import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.k.demo.entity.CustomerUser;
import com.k.demo.entity.ShoppingCart;
import com.k.demo.service.ShoppingCartService;

@RestController
@RequestMapping("cart")
public class ShoppingCartController {
	@Autowired
	private ShoppingCartService service;
	
	@RequestMapping("/mycart")
	public Object all(HttpSession session){
		Map<String,Object> map=new HashMap<String,Object>();
		CustomerUser user=(CustomerUser)session.getAttribute("loginUser");
		ShoppingCart cart=service.getCart(user.getUser_id());
		//ShoppingCart cart=service.getCart(1);
		if(cart!=null) {
			map.put("cart", cart);
		}
		map.put("msg",cart!=null);
		return map;
	}
	
}
